package com.ithema.controller;

import com.ithema.domain.Product;
import com.ithema.service.ProductService;
import com.ithema.util.JsonConverter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description
 * @Author wangyu
 * @Date 2021/10/31
 */
@Slf4j
@RestController
public class ProductController implements JsonConverter {

    @Autowired
    private ProductService productService;

    @Autowired
    private DiscoveryClient discoveryClient;

    @RequestMapping("/product/{pid}")
    public Product product(@PathVariable("pid") Integer pid){
        log.info("pid={}", pid);
        Product product = productService.findByPid(pid);
        log.info("product={}", toJson(product));
        return product;
    }

}
